/**
 * Created by fangshufeng on 2017/9/15.
 */

import  React from 'react';


function WarningBanner(props) {

    if (!props.showWarning) {
        return null;
    }
    return (<div>
        Warning!
    </div>);
};


export default class  Page extends  React.Component {

    constructor(props) {
        super(props);

        this.state = {
            showWarning:true,
        }
    }
    buttonDidClick = () => {
        // this.setState({
        //     showWarning:!this.state.showWarning,
        // });
        this.setState((preState,props)=>({
            showWarning:!preState.showWarning
        }));
    }
    render(){
        return (
            <div>
                <WarningBanner showWarning={this.state.showWarning}/>
                <button onClick={this.buttonDidClick}> 点我切换</button>
            </div>

        );
    }
}
    